package com.itheima.mall.web.sms;

import com.itheima.mall.pojo.sms.SmsFlashPromotion;
import com.itheima.mall.vo.PageResult;
import com.itheima.mall.vo.R;
import com.itheima.mall.service.sms.SmsFlashPromotionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("flash")
public class SmsFlashPromotionController {
    @Autowired
    SmsFlashPromotionService smsFlashPromotionService;

    /**
     * 添加活动
      * @param smsFlashPromotion
     * @return
     */
    @PostMapping("create")
    public R addActivity(@RequestBody SmsFlashPromotion smsFlashPromotion){
         smsFlashPromotionService.addActivity(smsFlashPromotion);
        return R.succeed(null,"添加成功");
     }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public R deleteActivity(@PathVariable Integer id){
        smsFlashPromotionService.deleteActivity(id);
        return R.succeed(null,"删除成功");
    }

    /**
     * 根据活动名称分页查询
     * @return
     */
    @GetMapping("/list")
    public R<PageResult<SmsFlashPromotion>> getList(@RequestParam(value = "keyword",required = false) String keyword, @RequestParam("pageNum")int pageNum, @RequestParam("pageSize")int pageSize){
        PageResult<SmsFlashPromotion> list = smsFlashPromotionService.getList(keyword, pageNum, pageSize);
        return R.succeed(list,"查询成功");
    }

    /**
     * 修改活动状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public R<String> updateStatus(@PathVariable int id,@RequestParam("status")int status){
        smsFlashPromotionService.updateStatus(id,status);
        return R.succeed(null,"修改成功");
    }

    /**
     * 编辑活动
     */
    @PostMapping("/update/{id}")
    public R<String> editActivity(@RequestBody SmsFlashPromotion smsFlashPromotion,@PathVariable Long id){
        smsFlashPromotionService.editActivity(smsFlashPromotion,id);
        return  R.succeed(null,"编辑成功");
    }
}
